package com.some;

public class ShenXin_01 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param st string字符串
     * @return string字符串
     */
    public static String get_substr(String st) {
        // write code here
        String res = st;
        char[] string = st.toCharArray();
        int i = 0, j;
        boolean found = false;
        while (i < string.length) {
            j = i + 1;
            int num = 2;
            char tmp = string[i];
            while (j + 1 < string.length && string[i] == string[j] && string[j] == string[j + 1]) {
                num++;
                j++;
                found = true;
            }
            if (found) {
                StringBuilder tmpStr = new StringBuilder();
                for (int k = 0; k < num; k++) {
                    tmpStr.append(tmp);
                }
                res = res.replace(tmpStr.toString(), "");
                string = res.toCharArray();
                if (i != 0)//回溯索引
                    i = 0;
                found = false;
            } else
                i++;
        }
        return res;
    }


    public static void main(String[] args) {
        System.out.println(get_substr("222BCC111CB"));
    }
}
